package com.aplink.generic.constant.type;

import sdt.brc.android.BarcodeReader;

public enum BarcodeType {
	SDTBARCODE_ALL_1D(BarcodeReader.SDTBARCODE_ALL_1D),
	SDTBARCODE_ALL_2D(BarcodeReader.SDTBARCODE_ALL_2D),
	SDTBARCODE_QRCODE(BarcodeReader.SDTBARCODE_QRCODE);
	public static BarcodeType get(final int type) {
		for (final BarcodeType barcodeType : BarcodeType.values()) {
			if (barcodeType.mValue == type) {
				return barcodeType;
			}
		}
		return BarcodeType.SDTBARCODE_ALL_1D;
	}

	public static int get(final String stringType) {
		if (stringType != null) {
			String[] type = null;
			if (stringType.contains(";")) {
				type = stringType.split(";");
			} else {
				type = new String[] { stringType };
			}
			int defaultValue = 0;
			for (final String s : type) {
				if (s.equalsIgnoreCase("1D")) {
					defaultValue = defaultValue
							| BarcodeReader.SDTBARCODE_ALL_1D;
				} else if (s.equalsIgnoreCase("2D")) {
					defaultValue |= BarcodeReader.SDTBARCODE_ALL_2D;
				} else if (s.equalsIgnoreCase("QR")) {
					defaultValue |= BarcodeReader.SDTBARCODE_QRCODE;
				}
			}
			return defaultValue;
		}
		return 0;
	}

	private int mValue;

	private BarcodeType(final int value) {
		setValue(value);
	}

	public int getValue() {
		return this.mValue;
	}

	public void setValue(final int value) {
		this.mValue = value;
	}
}
